<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <!-- 查询区域 -->
      <div class="search-box">
        <el-form-item label="商品名称" prop="productName">
          <el-input
            v-model="queryParams.productName"
            placeholder="请输入商品名称查询"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="所在仓库" prop="warehouseName">
          <el-select v-model="queryParams.warehouseId" placeholder="请选择" clearable>
            <el-option
              v-for="list in warehouses"
              :key="list.warehouseId"
              :label="list.warehouseName"
              :value="list.warehouseId"
            />
          </el-select>
        </el-form-item>
      </div>
      <!--按钮组-->
      <div class="search-btn">
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </div>
      <!--数据展示区-->
      <div class="data-box">
        <el-table v-loading="loading" :data="productList">
          <el-table-column type="index" label="序号" align="center" width="80"/>
          <el-table-column label="商品名称" align="center" prop="productName"/>
          <el-table-column label="商品图片" align="center" prop="imageUrl">
            <template slot-scope="scope">
              <el-image :src="scope.row.imageUrl" style="width: 100px; height: 100px" fit="contain"></el-image>
            </template>
          </el-table-column>
          <el-table-column label="所在仓库" align="center" prop="warehouseName"/>
          <el-table-column label="库存数量" align="center" prop="stockQuantity"/>
        </el-table>
      </div>
      <!--分页-->
      <div class="pagination-box">
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </el-form>
  </div>
</template>

<script>
import {
  getInventoryProductList,
  listWarehouse
} from "@/api/erp/inventoryproduct";

export default {
  name: "inventoryproduct",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,

      // 总条数
      total: 0,
      // 商品列表
      productList: [],
      // 仓库列表
      warehouses: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,

      }
    }
  },
  // 页面加载时执行
  created() {
    // 调用查询方法
    this.getList()
    this.getWarehouseList()
  },
  methods: {
    /** 查询库存商品列表 */
    getList() {
      // 遮罩层开启
      this.loading = true
      // 调用接口查询
      getInventoryProductList(this.queryParams).then(response => {
        this.productList = response.rows
        this.total = response.total
        // 遮罩层关闭
        this.loading = false
      })
    },
    // 查询商品仓库列表
    getWarehouseList() {
      // 调用查询方法
      listWarehouse().then(response => {
        this.warehouses = response.rows
      })
    },
    // 查询方法
    handleQuery() {
      this.getList()
    },
    // 重置方法
    resetQuery() {
      // 清空查询参数
      this.queryParams.warehouseId = ''
      this.resetForm('queryForm')
      // 重新查询
      this.handleQuery()
    },
  }
}
</script>

<style scoped lang="scss">

</style>
